﻿using Domain.Production_Modules;
using MediatR;
using MES.Server.API.Application.Command.InvoiceTicket.Invoice;
using MES.Server.API.Application.Command.InvoiceTicket.order;
using MES.Server.API.Application.Command.InvoiceTicket.Ticket;
using MES.Server.API.Dto.InvoiceTicketDTO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ReturnValue;

namespace MES.Server.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class InvoiceTicketController : ControllerBase
    {
        IMediator mediator;
        public InvoiceTicketController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 开票显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<InvoiceDto>>> InvoiceShow()
        {
            InvoiceQueryCommand command= new InvoiceQueryCommand();
            return mediator.Send(command);
        }
        /// <summary>
        /// 到票显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<GetTicketDto>>> TicketShow()
        {
            TicketQueryCommand command = new TicketQueryCommand();
            return mediator.Send(command);
        }
        /// <summary>
        /// 出库添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddInvoice([FromBody]InvoiceCreateCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 订单分页
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiPaging<OrderModel>> Getorder([FromQuery]GetOrderQueryCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 出库添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddTicket([FromBody]TicketCreateCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 更新开票金额并更新订单已付金额
        /// </summary>
        /// <param name="request">更新请求</param>
        /// <returns>处理结果</returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateInvoice([FromBody]InvoiceUpdateCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 添加发票金额到订单付款
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <returns>处理结果</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddInvoicePayment([FromBody]AddInvoicePaymentCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 添加订单
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <returns>处理结果</returns>
        [HttpPost]
        public async Task<ApiResult<int>> Addorder([FromBody] OrderCreateCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取开票记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<GetInvoicingDTO>> GetInvoicings([FromQuery]GetInvoicingCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取到票记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<GetTicketDto>> GetTickets([FromQuery]GetTicketCommand request)
        {
            return mediator.Send(request);
        }
    }
}
